package com.vincent.kdp.ui.commodity;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.vincent.baseapp.base.BaseActivity;
import com.vincent.kdp.R;
import com.vincent.kdp.ui.adapter.LikeCommoditiesAdapter;
import com.vincent.kdp.ui.adapter.SuggestCommoditiesAdapter;
import com.vincent.kdp.ui.bean.entity.CommodityDetail;
import com.vincent.kdp.ui.bean.entity.LikeCommodity;
import com.vincent.kdp.ui.commodity.contract.CommodityDetailContract;
import com.vincent.kdp.ui.commodity.presenter.CommodityDetailPresenter;

import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;

public class CommodityDetailActivity extends BaseActivity<CommodityDetailContract.View, CommodityDetailPresenter>
        implements CommodityDetailContract.View {


    @Bind(R.id.back_img)
    ImageView mBackImg;
    @Bind(R.id.toolbar_center_tv)
    TextView mToolbarCenterTv;
    @Bind(R.id.commodity_img)
    ImageView mCommodityImg;
    @Bind(R.id.recycleView_like)
    RecyclerView mRecycleViewLike;
    @Bind(R.id.recycleView_suggest)
    RecyclerView mRecycleViewSuggest;

    @Bind(R.id.commodity_name_tv)
    TextView mCommodityNameTv;
    @Bind(R.id.price_tv)
    TextView mPriceTv;
    @Bind(R.id.style_num_tv)
    TextView mStyleNumTv;
    @Bind(R.id.style_tv)
    TextView mStyleTv;
    @Bind(R.id.series_tv)
    TextView mSeriesTv;
    @Bind(R.id.material_colour_tv)
    TextView mMaterialColourTv;
    @Bind(R.id.craft_tv)
    TextView mCraftTv;
    @Bind(R.id.hand_inch_tv)
    TextView mHandInchTv;
    @Bind(R.id.main_stone_name_tv)
    TextView mMainStoneNameTv;
    @Bind(R.id.main_stone_weight_tv)
    TextView mMainStoneWeightTv;
    @Bind(R.id.main_stone_clarity_tv)
    TextView mMainStoneClarityTv;

    @Bind(R.id.main_stone_color_tv)
    TextView mMainStoneColorTv;

    @Bind(R.id.main_stone_unit_tv)
    TextView mMainStoneUnitTv;

    @Bind(R.id.domestic_certificate_tv)
    TextView mDomesticCertificateTv;
    @Bind(R.id.intl_certificate_tv)
    TextView mIntlCertificateTv;

    @Bind(R.id.main_stone_num_tv)
    TextView mMainStoneNumTv;

    @Bind(R.id.vice_stone_num_tv)
    TextView mViceStoneNumTv;
    @Bind(R.id.vice_stone_weight_tv)
    TextView mViceStoneWeightTv;
    @Bind(R.id.vice_stone_unit_tv)
    TextView mViceStoneUnitTv;
    @Bind(R.id.accessory_tv)
    TextView mAccessoryTv;
    @Bind(R.id.polish_tv)
    TextView mPolishTv;
    @Bind(R.id.metal_color_tv)
    TextView mMetalColorTv;
    @Bind(R.id.total_weight_tv)
    TextView mTotalWeightTv;
    @Bind(R.id.accessory_chain_tv)
    TextView mAccessoryChainTv;
    @Bind(R.id.chain_length_tv )
    TextView mChainLengthTv;
    @Bind(R.id.letterable_tv)
    TextView mLetterableTv;
    @Bind(R.id.charge_unit_tv)
    TextView mChargeUnitTv;
    @Bind(R.id.labor_cost_tv)
    TextView mLaborCostTv;
    @Bind(R.id.crowd_tv)
    TextView mCrowdTv;
    @Bind(R.id.look_times_tv)
    TextView mLookTimesTv;
    @Bind(R.id.net_gold_weight_tv)
    TextView mNetGoldWeightTv;


    private LikeCommoditiesAdapter mLikeCommoditiesAdapter;
    private SuggestCommoditiesAdapter mSuggestCommoditiesAdapter;

    @Override
    public int getLayoutResId() {
        return R.layout.activity_commodity_detail;
    }

    @Override
    public void initViewData() {
        presenter.initView(getIntent());
//        initLikeRecycle();
//        initSuggestRecycle();
    }

    private void initSuggestRecycle() {
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        mRecycleViewSuggest.setLayoutManager(layoutManager);
        mSuggestCommoditiesAdapter = new SuggestCommoditiesAdapter(this, suggestClicker);
        mRecycleViewSuggest.setAdapter(mSuggestCommoditiesAdapter);
    }

    @Override
    public void initLikeRecycle(List<LikeCommodity> likeCommodityList) {
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        mRecycleViewLike.setLayoutManager(layoutManager);
        mLikeCommoditiesAdapter = new LikeCommoditiesAdapter(this, likeCommodityList, checkedItemClicker);
        mRecycleViewLike.setAdapter(mLikeCommoditiesAdapter);
    }

    @Override
    public void refreshCommodityDetail(CommodityDetail commodityDetail) {
        mPriceTv.setText("￥" + commodityDetail.getPrice());
        mStyleNumTv.setText("款号：" + commodityDetail.getStyleNum());
        mStyleTv.setText("款式：" + commodityDetail.getStyle());
        mSeriesTv.setText("系列：" + (commodityDetail.getSeries()==null?"无":commodityDetail.getSeries()));
        mMaterialColourTv.setText("材质：" + commodityDetail.getMaterialColour());
        mCraftTv.setText("工艺特色：" + commodityDetail.getCraft());
        mHandInchTv.setText("尺寸：" + commodityDetail.getHandInch());
        mMainStoneNameTv.setText("主石特色：" + commodityDetail.getMainStoneName());
        mMainStoneWeightTv.setText("主石重量：" + commodityDetail.getMainStoneWeight());
        mMainStoneClarityTv.setText("主石净度：" + commodityDetail.getMainStoneClarity());
        mCommodityNameTv.setText(commodityDetail.getName());

        mDomesticCertificateTv.setText("国内证书编号："+commodityDetail.getDomesticCertificate());
        mIntlCertificateTv.setText("国际证书编号："+commodityDetail.getIntlCertificate());
        mViceStoneNumTv.setText("副石编号："+commodityDetail.getViceStoneNum());
        mViceStoneWeightTv.setText("副石重："+commodityDetail.getViceStoneWeight());
        mViceStoneUnitTv.setText("副石单位："+commodityDetail.getViceStoneUnit());
        mNetGoldWeightTv.setText("净金重："+commodityDetail.getNetGoldWeight());
        mMainStoneNumTv.setText("主石编号："+commodityDetail.getMainStoneNum());
        mMainStoneColorTv.setText("主石颜色："+commodityDetail.getMainStoneColor());
        mMainStoneUnitTv.setText("主石单位："+commodityDetail.getMainStoneUnit());
        mAccessoryTv.setText("配件："+commodityDetail.getAccessory());
        mPolishTv.setText("打磨："+commodityDetail.getPolish());
        mMetalColorTv.setText("金属色："+ (commodityDetail.getMetalColor()==null?"无":commodityDetail.getMetalColor()));
        mTotalWeightTv.setText("总重："+commodityDetail.getTotalWeight());
        mAccessoryChainTv.setText("配链："+commodityDetail.getAccessoryChain());
        mChainLengthTv.setText("配链长度："+commodityDetail.getChainLength());
        mLetterableTv.setText("是否可刻字："+(commodityDetail.getLetterable().equals("1")?"可刻字":"不可刻字"));
        mChargeUnitTv.setText("计价单位："+commodityDetail.getChargeUnit());
        mLaborCostTv.setText("人工费："+commodityDetail.getLaborCost());
        mCrowdTv.setText("适合人群："+commodityDetail.getCrowd());

        mLookTimesTv.setText("看货次数："+ (commodityDetail.getLookTimes()==null?0:commodityDetail.getLookTimes()));
        Glide.with(this).load(commodityDetail.getImageUrl()).placeholder(R.mipmap.ic_default_image).into(mCommodityImg);
    }

    private LikeCommoditiesAdapter.OnCheckedItemClicker checkedItemClicker = new LikeCommoditiesAdapter
            .OnCheckedItemClicker() {
        @Override
        public void onItemChecked(View view, int newPosition, int itemCount) {

        }
    };
    private SuggestCommoditiesAdapter.OnCheckedItemClicker suggestClicker = new SuggestCommoditiesAdapter
            .OnCheckedItemClicker() {
        @Override
        public void onItemChecked(View view, int newPosition, int itemCount) {

        }
    };

    @OnClick(R.id.back_img)
    public void onClick() {
        actFinish();
    }

    @Override
    public CommodityDetailPresenter initPresenter() {
        return new CommodityDetailPresenter();
    }
}
